package core.network.client2game.handler.tdk;

import business.global.pk.tdk.TDKRoom;
import business.global.room.RoomMgr;
import business.tdk.c2s.cclass.TDKResults;
import business.player.Player;
import com.ddm.server.websocket.def.ErrorCode;
import com.ddm.server.websocket.handler.requset.WebSocketRequest;
import com.google.gson.Gson;
import core.network.client2game.handler.PlayerHandler;
import jsproto.c2s.iclass.room.CBase_GetRoomInfo;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

public class CTDKRoomXRecord extends PlayerHandler {


    @Override
    public void handle(Player player, WebSocketRequest request, String message) throws IOException {
        final CBase_GetRoomInfo req = new Gson().fromJson(message, CBase_GetRoomInfo.class);
        long roomID = req.getRoomID();

        TDKRoom room = (TDKRoom) RoomMgr.getInstance().getRoom(roomID);
        if (null == room){
            request.error(ErrorCode.NotAllow, "CTDKRoomEndResult not find room:"+roomID);
            return;
        }
        List<TDKResults> results = room.getRoomPosMgr().getPosList().stream().filter(k -> k.getPid() > 0L && k.isPlayTheGame())
                .map(k -> (TDKResults)k.getResults()).filter(n->n!=null).collect(Collectors.toList());
        request.response(results);
    }
}
